from typing import Any, Optional
from pydantic import BaseModel
    
    # 定义 ResultBase 类
class ResultBase:
    code: str
    msg: str
    data: Optional[Any] = None

# 定义 ResultModel 类（继承自 BaseModel 和 ResultBase）
class ResultModel(BaseModel, ResultBase):
    pass

# 定义 Result 类
class Result(ResultModel):
    def __init__(self, code: str, msg: str, data: Optional[Any] = None):
        super().__init__(code=code, msg=msg, data=data)

    @classmethod
    def success(cls, data: Optional[Any] = None, code: str = "200", msg: str = "success"):
        return cls(code=code, msg=msg, data=data)

    @classmethod
    def error(cls, data: Optional[Any] = None, code: str = "500", msg: str = "error"):
        return cls(code=code, msg=msg, data=data)